package com.web.dao;

import com.web.entity.Goods;

import static org.apache.ibatis.jdbc.SqlBuilder.*;

/**
 * @author FDjavaone
 */
public class GoodsSqlProvider {


    public String insertSelective(Goods record) {
        BEGIN();
        INSERT_INTO("t_goods");

        if (record.getMenuId() != null) {
            VALUES("menu_id", "#{menuId,jdbcType=BIGINT}");
        }

        if (record.getTitle() != null) {
            VALUES("title", "#{title,jdbcType=VARCHAR}");
        }

        if (record.getImage() != null) {
            VALUES("image", "#{image,jdbcType=VARCHAR}");
        }

        if (record.getPrice() != null) {
            VALUES("price", "#{price,jdbcType=DECIMAL}");
        }

        if (record.getNum() != null) {
            VALUES("num", "#{num,jdbcType=INTEGER}");
        }

        if (record.getCreateTime() != null) {
            VALUES("create_time", "#{createTime,jdbcType=TIMESTAMP}");
        }

        if (record.getModifyTime() != null) {
            VALUES("modify_time", "#{modifyTime,jdbcType=TIMESTAMP}");
        }

        return SQL();
    }


    public String updateByPrimaryKeySelective(Goods record) {
        BEGIN();
        UPDATE("t_goods");

        if (record.getMenuId() != null) {
            SET("menu_id = #{menuId,jdbcType=BIGINT}");
        }

        if (record.getTitle() != null) {
            SET("title = #{title,jdbcType=VARCHAR}");
        }

        if (record.getImage() != null) {
            SET("image = #{image,jdbcType=VARCHAR}");
        }

        if (record.getPrice() != null) {
            SET("price = #{price,jdbcType=DECIMAL}");
        }

        if (record.getNum() != null) {
            SET("num = #{num,jdbcType=INTEGER}");
        }

        if (record.getCreateTime() != null) {
            SET("create_time = #{createTime,jdbcType=TIMESTAMP}");
        }

        if (record.getModifyTime() != null) {
            SET("modify_time = #{modifyTime,jdbcType=TIMESTAMP}");
        }

        WHERE("id = #{id,jdbcType=BIGINT}");

        return SQL();
    }


}